//
//  WBWelcomeView.swift
//  微博
//
//  Created by 康智桐 on 2018/4/22.
//  Copyright © 2018年 Kk. All rights reserved.
//

import UIKit
import SDWebImage

//欢迎视图
class WBWelcomeView: UIView {

    
    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!
    
    @IBOutlet weak var bottom: NSLayoutConstraint!
    
    
    class func welcomeView()->WBWelcomeView{
        
        let nib = UINib(nibName: "WBWelcomeView", bundle: nil)
        
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! WBWelcomeView
        
        v.frame = UIScreen.main.bounds
        
        
        return v
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder:aDecoder)
    }
    override func awakeFromNib() {
        guard let urlString = WBNetworkManager.shared.userAccount.avatar_large,
           let url = URL(string: urlString) else {
            return
        }
        iconView.sd_setImage(with: url, placeholderImage: UIImage(named: "avatar_default_big"))
        //设置圆角
        iconView.layer.cornerRadius = 42.5
        iconView.layer.masksToBounds = true
        
        
    }
    
    
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        
        self.layoutIfNeeded()
        
        bottom.constant = bounds.size.height - 250
        
        
        
        
        UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            
            self.layoutIfNeeded()
            
        }){(_) in
            
            UIView.animate(withDuration: 1.0, animations: {
                self.tipLabel.alpha = 1
                }, completion: { (_) in
              
                    self.removeFromSuperview()
                    
            })
            
        }
        
    }

}
